<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>超级电容启动电源</title>
    <style>
        body {
            font-size: 16px;
            color: #666;
        }
        button {
            min-width: 5rem;
            height: 2.4rem;
            font-size: 1em;
        }
        select {
            font-size: 1em;
            height: 2.4rem;
        }
        input {
            font-size: 1em;
            height: 2rem;
            width: 3rem;
        }
        .green {
            color: forestgreen;
        }
        .red {
            color: red;
        }
        .blue {
            color: blue;
        }
        .orange {
            color: orange;
        }
        .bold {
            font-weight: bold;
        }
        .tips {
            width: 1.5em;
            height: 1.5em;
            border: 1px solid #ccc;
            border-radius: 3em;
            color: #fff;
            background-color: #ccc;
            margin: 0;
            padding: 0;
            display: inline-flex;
            font-size: 0.7em;
            justify-content: center;
            align-items: center;
            user-select: none;
        }
        .info {
            border: 1px solid #ccc;
            width: 500px;
            padding: 0 1rem 1rem;
            margin-top: 1rem;
        }
        .info-line {
            display: flex;
            justify-content: space-between;
            margin-top: 2rem;
            align-items: center;
        }
        .info-line2 {
            justify-content: flex-start;
        }
        .info-line div {
            width: 50%;
        }

    </style>
</head>
<body>
<div id="main">
    <input id="test-data" value="12.04-12.21-0.10-17.81-28-15.00-100-0-0-1-2-0-6-2-80-0-0-1-0" id="readValue" style="width:100%; display: none;"/>
    <div style="text-align: center; margin-top: 1rem;">
        <button id="connect-btn" onclick="connect()">连接蓝牙设备</button>
    </div>
    <div id="info" style="display: flex; width: 1000px; margin: 0 auto;">
        <div class="info" >
            <div class="info-line" style="justify-content: center">
                <div >
                    电量：<span id="power" class="red bold" style="font-size: 3em">--</span>%
                </div>
            </div>
            <div class="info-line">
                <div >
                    电瓶电压：<span id="bat-v" class="green bold">--</span>V
                </div>
                <div >
                    USB电压：<span id="usb-v" class="green bold">--</span>V
                </div>
            </div>
            <div class="info-line">
                <div >
                    电容电压：<span id="cap-v" class="green bold">--</span>V
                </div>
                <div >
                    电容温度：<span id="cap-c" class="green bold">--</span>&#8451;
                </div>
            </div>
            <div class="info-line">
                <div >
                    充电速度：<span id="cha-s" class="green bold">--</span>%
                </div>
                <div >
                    截止电压：<span id="cha-v" class="green bold">--</span>V
                    <p class="tips" onclick="showTips(event, '车载稳压使用模式下电容的充满截止电压')" >?</p>
                </div>
            </div>
            <div class="info-line">
                <div >
                    照明状态：<span id="lig-ss" class="bold">--</span>
                </div>
                <div >
                    照明亮度：<span id="lig-b" class="green bold">--</span>%
                </div>

            </div>
            <div class="info-line">
                <div >
                    照明开启：<span id="lig-s" class="bold">--</span>
                </div>
                <div >
                    放电状态：<span id="dis-s" class="bold">--</span><span id="dis-timer" class="bold orange" style="display: none">10</span>
                </div>

            </div>
            <div class="info-line">
                <div >
                    放电保护：<span id="dis-l" class="bold">--</span>
                </div>
                <div >
                    放电模式：<span id="dis-m" class="bold green">--</span>
                </div>

            </div>
            <div class="info-line">
                <div >
                    用途模式：<span id="mod" class="bold green">--</span>
                </div>
                <div>
                    自放灵敏度：<span id="auto-v" class="green bold">--</span>
                    <p class="tips" onclick="showTips(event, '值越大越容易触发救援模式的自动放电')" >?</p>
                </div>
            </div>
            <div class="info-line">
                <div style="width: 100%">
                    车放灵敏度：<span id="car-v"  class="green bold">--</span>
                    <p class="tips" onclick="showTips(event, '值越大越早触发车载模式的接通放电，0仅在点火时接通，1电容与电瓶电压相等时无电流冲击接通')">?</p>
                </div>
            </div>
        </div>
        <div class="info">
            <div class="info-line">
                <button id="lig-ss-btn" onclick="sendValue('14-001')">启用照明</button>
                <button id="lig-s-btn" onclick="sendValue('01-001')">开灯</button>
            </div>
            <div class="info-line">
                <button id="dis-conn-btn" onclick="disconnect()">断开蓝牙</button>
                <button id="off-btn" onclick="sendValue('13-001', event, true)">关机</button>
            </div>
            <div class="info-line">
                <button id="auto-btn" onclick="sendValue('02-001', event, true)">自动放电</button>
                <button id="timer-btn" onclick="sendValue('03-001', event, true)">倒计时放电</button>
                <button id="manual-btn" onclick="sendValue('04-001', event, true)">手动放电</button>
            </div>
            <div class="info-line">
                <button id="off-cha-btn" onclick="sendValue('05-001', event, true)">关闭放电</button>
            </div>
            <div class="info-line info-line2">
                放电模式：
                <select id="dis-m-opt" >
                    <option value="0">有电瓶</option>
                    <option value="1">无电瓶</option>
                    <option value="2">全手动</option>
                </select>
                <button onclick="sendValue('06-00' + document.getElementById('dis-m-opt').value)"  >更改</button>
            </div>
            <div class="info-line info-line2">
                用途模式：
                <select id="mod-opt" style="">
                    <option value="0">应急救援</option>
                    <option value="1">车载稳压</option>
                </select>
                <button onclick="sendValue('07-00' + document.getElementById('mod-opt').value)" >更改</button>
            </div>
            <div class="info-line info-line2">
                充电速度(%)：
                <input type="number" id="cha-s-in" value="" min="0" max="100">
                <button onclick="changeChaS(document.getElementById('cha-s-in').value)" >更改</button>
                <p class="tips" onclick="showTips(event, '取值范围：0-100')" style="margin-left: 2em" >?</p>
            </div>
            <div class="info-line info-line2">
                照明亮度(%)：
                <input type="number" id="lig-b-in" value="" min="1" max="100">
                <button onclick="changeLigB(document.getElementById('lig-b-in').value)" >更改</button>
                <p class="tips" onclick="showTips(event, '取值范围：1-100')" style="margin-left: 2em" >?</p>
            </div>
            <div class="info-line info-line2">
                截止电压(V)：
                <input type="number" id="cha-v-in" value="" min="0.0" max="15.0">
                <button onclick="changeChaV(document.getElementById('cha-v-in').value)">更改</button>
                <p class="tips" onclick="showTips(event, '车载稳压使用模式下电容的充满截止电压。取值范围：0.0-15.0')" style="margin-left: 2em" >?</p>
            </div>
            <div class="info-line info-line2">
                自动放电灵敏度：
                <input type="number" id="auto-v-in" value="" min="1" max="9">
                <button onclick="changeAutoV(document.getElementById('auto-v-in').value)">更改</button>
                <p class="tips" onclick="showTips(event, '值越大越容易触发救援模式的自动放电。取值范围：1-9')" style="margin-left: 2em" >?</p>
            </div>
            <div class="info-line info-line2">
                车载放电灵敏度：
                <input type="number" id="car-v-in" value="" min="0" max="9">
                <button onclick="changeCarV(document.getElementById('car-v-in').value)">更改</button>
                <p class="tips" onclick="showTips(event, '值越大越早触发车载模式的接通放电，0仅在点火时接通，1电容与电瓶电压相等时无电流冲击接通。取值范围：0-9')" style="margin-left: 2em" >?</p>
            </div>
        </div>
    </div>

</div>

<script src="./bluetooth.js"></script>
<script src="opt2.js"></script>
<script>
    const mainDiv = document.getElementById('main');
    if (!('bluetooth' in navigator)) {
        mainDiv.innerHTML = '抱歉，您的浏览器不支持蓝牙连接，请使用谷歌（Chrome）或Edge浏览器访问该页面。';
    } else {
        init();
    }
</script>
</body>
</html>